/***************************************************************************
 *   Copyright (C) 2011  by TinySofts                                      *
 *   tinysofts@gmail.com                                                   *
 *   All Rights Reserved.                                                  *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   Refer to http://code.google.com/p/tinydict/                           *
 ***************************************************************************/

/*
    UI & func of TinyDict
    Status:Open;ReleaseReady;M
*/

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QtGui>
#include "tdict.h"
#include "babylondict.h"
#include "basedict.h"

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = 0);
    ~MainWindow() {}
    bool eventFilter(QObject *, QEvent *);

public slots:
    void showContextMenu(const QPoint & pos);
    void notImplement();
    void interpretationTextChanged(const QString & w);
    void interTextChanged(const QString & w);
    void batchClicked();
    void regStarDict();
    void regBabylonDict();
    void buildBabylonDict();
    void unregisterDict();
    void setDefaultDict();
    void showDictInfo();
    void add2TinyDict();
    void showAbout();
    void changeMode(bool);
    void runSpecial();
    void setWordFile();
    void initConfig();
    void clearDictInfo();
    void add2NewWord();
    void systrayClicked(QSystemTrayIcon::ActivationReason reason);
    void initBabylonDicts();
  
private:
    void createMenuBar();
    void createComponent();
    void createUi();
    void createSystray();

    bool loadAppDB();
    QString getConfig(QString key);
    int setConfig(QString key, QString value);
    QByteArray lookUpDict(const QString & word);
    QByteArray lookUpDict2(const QString & word);

private:
    QWidget * mainWidget;
    int _seq;
    int _lastseq;
    int _dicttype;
    QString _path;
    QString _filename;
    QString _wordFile;
    /*ACTIONS*/
    QAction * modAction;
    QAction *aboutAction;
    QAction *quitAction;
    QAction *batchAction;
    /*Menu*/
    QMenuBar *menuBar;
    QMenu *menuMain;
    QMenu *menuQuery;
    QMenu *menuAdmin;
    QMenu *menuTool;
    QMenu *menuHelp;
    QToolBar *mainToolBar;
    QStatusBar *statusBar;
    /*UI*/
    QWidget *centralWidget;
    QVBoxLayout * mainLayout;
    QPushButton * addNewButton;
    QLabel *promtLabel;
    QLineEdit *inputWord;
    QListWidget *dictList;
    QTextEdit *explText;
    TDict * tdict;
    BabylonDict * bdict;

    BaseDict * currDict;
    int _mode;
};

#endif // MAINWINDOW_H
